﻿/* $RCSFile: Attach2CrmForm.ascx.cs $
 * Apache license v2 2011 by Christian Surieux
 * $Source: ?/AddonNice/PageModules/Attach2CrmForm/Attach2CrmForm.ascx.cs $
 * $log$
 * Revision 20 2010/08/09 10:51:18  christian.surieux
 *   Added Log comment to all .aspx .ascx .master files
 * Revision 19 2010/08/09 09:43:45  christian.surieux
 *   Added Log to cs sources files
 * Revision 6 2010/08/06 19:56:24  christian.surieux
 *   Added Log to All cs files
 */

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;  
using System.Web.UI.WebControls;
using System.Diagnostics;
using System.Drawing;
using System.Text;
using System.Data.SqlClient;
using System.Web.Services.Protocols;
using System.Globalization;

using AddonNice.Core;
using AddonNice.UI;
using AddonNice.Design;
using AddonNice.UI.WebControls;
using AddonNice.Security;
using AddonNice.UI.DataTypes;
using AddonNice.Configuration;
using AddonNice.Configuration.Settings;
using AddonNice.Diagnostics;
using AddonNice.Helpers;
using AddonNice.Settings;

using AddonNice.CRMWrapper;
using CrmSdk;
using CrmSdk.CRM4;

using Telerik.Web.UI;

using Trace2    =   System.Diagnostics.Trace;


namespace AddonNice.PageModules.Attach2CrmForm
{
    public class AStr
    {
            public const string showAdmin           =   "ATTACH2CRM_SHOW_ADMIN";
            public const string skipList            =   "ATTACH2CRM_PAGES_SKIP_LIST";
    }

    /// <summary>
    /// Initializer class for announcements 
    /// </summary>
    public class Attach2CrmFormSI : PortalCRMModuleControlSI
    {
        public Attach2CrmFormSI(ModuleSettingsDictionary bSettings,ISettingsOwner pm) : base()
        {
            if ( ModuleTraceSwitch.Sw.TraceVerbose )
                Trace2.WriteLine( "[V]Attach2CrmFormSI Ctor BEG.",ModuleTraceSwitch.Sw.Info);
            InitSettings(bSettings,pm);
            if ( ModuleTraceSwitch.Sw.TraceVerbose )
                Trace2.WriteLine( "[V]Attach2CrmFormSI Ctor END.",ModuleTraceSwitch.Sw.Info);
        }
 
        public override void InitSettings(ModuleSettingsDictionary bSettings,ISettingsOwner pm)
        {             
            if ( ModuleTraceSwitch.Sw.TraceVerbose )
                Trace2.WriteLine( "[V]Attach2CrmFormSI InitSettings BEG.",ModuleTraceSwitch.Sw.Info);
            
            base.InitSettings(bSettings,pm);
            string extgrp                       =   pm.ExtendedResourcesGroup;

            // Admin pages : false by default
			SettingItemSpecial showAdmin	    =	new SettingItemSpecial(AStr.showAdmin,new BooleanDataType());
			showAdmin.Value		                =	"false";        
			showAdmin.Order		                =	10;        
			showAdmin.ExtendedGroupName         =   extgrp;
            showAdmin.Description		        =	"Should the module show site Admin pages";
			showAdmin.EnglishName		        =	"Show Admin";
			bSettings.AddSetting(showAdmin);

            // SkipPages List
			SettingItemSpecial skipList	        =	new SettingItemSpecial(AStr.skipList,new StringDataType());
			skipList.Order			            =	20;
			skipList.ExtendedGroupName          =   extgrp;
            skipList.Description		        =	"Semicolon separated list of page IDs that should be skipped";
			skipList.EnglishName		        =	"Page skip List";
			bSettings.AddSetting(skipList);
            if ( ModuleTraceSwitch.Sw.TraceVerbose )
                Trace2.WriteLine( "[V]Attach2CrmFormSI InitSettings END.",ModuleTraceSwitch.Sw.Info);
        }
    }

    public partial class Attach2CrmForm : PortalCRMModuleControl
    {

        #region General implementation

		/// <summary>
		/// Only 4
		/// </summary>
		public override VersionType ModuleType
		{
			get
			{
				return VersionType.CrmV4;
			}
		}

        public override bool AdminModule
        {
            get
            {
                return true;
            }
        }

        public override Guid GuidID
        {
            get
            {
                return new Guid("{457C372F-02ED-4176-81BC-34D8794B87FE}");
            }
        }
        #endregion General implementation

        /// <summary>
        /// No entity needed here
        /// </summary>
        public override bool NeedAttachedEntity
        {
            get
            {
                return false;
            }
        }

        ArrayList _AllEntities =   null;
        ArrayList GetAllEntities(bool useAll)
        {
            if (_AllEntities == null)
            {
                _AllEntities          =   MetadataCache.GetAllEntities(Wrapper,useAll);
            }
            return _AllEntities;
        }
        

        string StrNewTab        =   LocalizeHelper.Localize("ATTACH2CRM_NEWTAB","New Tab");
        string StrNewSection    =   LocalizeHelper.Localize("ATTACH2CRM_NEWSECTION","New Section");

        /// <summary>
        /// constructor installs validation group 'Main'
        /// </summary>
        public Attach2CrmForm()
        {
            ValidationGroup                     =   "Main";
        }
        
        public override string ExtendedResourcesGroup 
		{
            get
            {
                const string extgrp                 =   "ATTACH2CRM";
                return extgrp;
            }
		}
 
        public override void InitPortalModuleControl(ModuleSettingsDictionary bSettings)
        {
            PortalModuleInitializer =   new Attach2CrmFormSI(bSettings,this);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (ModuleTraceSwitch.Sw.TraceVerbose)
                Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]Attach2CrmForm Page_Load BEG IsPostBack: {0}",IsPostBack),ModuleTraceSwitch.Sw.Info);
   			// If first visit to the page, update all entries
			if ( !IsPostBack ) 
			{
                // Select by default Web Page
                PagesDropDownList.SelectedTreeViewValue     =   StStr.PageDemoCRMID.ToString();
                ArrayList are                               =   GetAllEntities(true);
                RadComboEntities.DataTextField              =   "displayName";
                RadComboEntities.DataValueField             =   "entityName";
                RadComboEntities.Sort                       =   RadComboBoxSort.Ascending;
                RadComboEntities.SortCaseSensitive          =   false;
                RadComboEntities.DataSource                 =   are;
                DataBind();
                RadComboEntities.DataBind();
                RadComboEntities.SortItems();
                if (ModuleTraceSwitch.Sw.TraceVerbose)
                    Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]Attach2CrmForm Page_Load  after DataBind PagesDropDownList.Text : [{0}].", PagesDropDownList.Text),ModuleTraceSwitch.Sw.Info);
			}
            if (ModuleTraceSwitch.Sw.TraceVerbose)
                Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]Attach2CrmForm Page_Load END IsPostBack: {0}",IsPostBack),ModuleTraceSwitch.Sw.Info);
        }

        private void FindSectionsInTab(string TabId,NodeUtil ndu,bool add)
        {
            for (int i = 0; i < ndu.Nodes.Count; i++)
            {
                NodeUtil nu     =   ndu.Nodes[i];
                RadTreeNode nd  =   new RadTreeNode(nu.Text);
                if (nu.Type == NodeType.Section && add)
                {
                    string scName = nu.Text.Replace("Section '", string.Empty).Trim(new char[] { '\'' });
                    RadComboSection.Items.Add(new RadComboBoxItem(scName,ndu.Id));
                }
                if (nu.Type == NodeType.Tab && TabId == nu.Id)
                {
                    add         =   true;
                    FindSectionsInTab(TabId, nu, add);
                    add         =   false;
                    return;
                }
                FindSectionsInTab(TabId, nu, add);
            }
        }

        void FillTreeView(TreeUtil fTree)
        {
            if (ModuleTraceSwitch.Sw.TraceVerbose)
                Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]Attach2CrmForm FillTreeView BEG fTree: {0}",fTree.Node.Text),ModuleTraceSwitch.Sw.Info);
            RadFormTree.UnselectAllNodes();
            RadFormTree.Nodes.Clear();
            RadTreeNode nd0         =   new RadTreeNode(fTree.Node.Text,fTree.Node.Id);
            RadFormTree.Nodes.Add(nd0);
            nd0.Expanded            =   true;
            
            RadComboTab.ClearSelection();
            RadComboTab.Items.Clear();
            RadComboBoxItem it0     =   new RadComboBoxItem(StrNewTab,string.Empty);
            RadComboTab.Items.Add(it0);
            it0.Selected            =   true;

            RadComboSection.ClearSelection();
            RadComboSection.Items.Clear();
            it0                     =   new RadComboBoxItem(StrNewSection,string.Empty);
            RadComboSection.Items.Add(it0);
            it0.Selected            =   true;
            FillNodes(nd0,fTree.Node);
            if (ModuleTraceSwitch.Sw.TraceVerbose)
                Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]Attach2CrmForm FillTreeView END Nodes.Count: {0}",RadFormTree.Nodes.Count),ModuleTraceSwitch.Sw.Info);
        }

        private void FillNodes(RadTreeNode nd0, NodeUtil ndu)
        {
            for (int i = 0; i < ndu.Nodes.Count; i++)
            {
                NodeUtil nu         =   ndu.Nodes[i];
                RadTreeNode nd      =   new RadTreeNode(nu.Text,nu.Id);
                if (nu.Type == NodeType.Tab)
                {
                    string tbName   =   nu.Text.Replace("Tab '",string.Empty).Trim(new char[]{'\''});
                    RadComboTab.Items.Add(new RadComboBoxItem(tbName,nu.Id));
                }
                nd0.Nodes.Add(nd);
                if ( nu.Type == NodeType.Form ||
                     nu.Type == NodeType.Tab
                    )
                    nd.Expanded     =   true;
                FillNodes(nd, nu);

            }
        }
        
        /// <summary>
        /// We export corresponding entity from CRM and build treeview with its data
        /// Also fill the Combo of Tabs and Sections (must be dynamic)
        /// </summary>
        void FillTree()
        {
            string selectedEntity   =   RadComboEntities.SelectedValue;
            CrmUtil4Form util       =   new CrmUtil4Form((CrmWrapper4)Wrapper,selectedEntity);
            util.ExportXml();
            TreeUtil fTree          =   util.BuildTree(true,true);
            FillTreeView(fTree);
        }

        void FillSummary(bool init)
        {
            string TabName                  =   RadComboTab.Text;
            string SectionName              =   RadComboSection.Text;
            string entDisplayName           =   RadComboEntities.Text;
            string PageName                 =   PagesDropDownList.Text;
            StringBuilder sb                =   new StringBuilder();
            string fmt                      =   LocalizeHelper.Localize("ATTACH2CRM_SUMMARYFMT1","Entity : {0}{1}");
            sb.AppendFormat(fmt, entDisplayName,StStr.strBr);
            fmt                             =   LocalizeHelper.Localize("ATTACH2CRM_SUMMARYFMT2","Page : {0}-{1}{2}");
            sb.AppendFormat(fmt, PagesDropDownList.Text,PagesDropDownList.SelectedValue,StStr.strBr);
            if ( TabName == StrNewTab )
            {
                if ( !string.IsNullOrEmpty(PageName) && ( rblUsePageName.SelectedValue == "Yes" ) )
                {
                    //TabName                 =   string.Format("{0} {1}",entDisplayName,PageName);
                    TabName                 =   PageName;
                    //SectionName             =   string.Format("{0} {1}",entDisplayName,PageName);
                    SectionName             =   PageName;
                }
                else 
                {
                    if ( !string.IsNullOrEmpty(TbTabName.Text) )
                        TabName             =   TbTabName.Text;
                    else TabName            =   string.Format("{0} {1}",entDisplayName,PageName);

                    if ( !string.IsNullOrEmpty( TbSectionName.Text) )
                        SectionName         =   TbSectionName.Text;
                    else SectionName        =   TabName;
                }
                fmt                         =   LocalizeHelper.Localize("ATTACH2CRM_SUMMARYFMT3A","New Tab name: {0}{1}");
                sb.AppendFormat(fmt, TabName,StStr.strBr);
                fmt                         =   LocalizeHelper.Localize("ATTACH2CRM_SUMMARYFMT3B","New Section name: {0}{1}");
                sb.AppendFormat(fmt, SectionName,StStr.strBr);
            }
            else 
            {
                fmt                             =   LocalizeHelper.Localize("ATTACH2CRM_SUMMARYFMT3","Tab : {0}{1}");
                sb.AppendFormat(fmt, TabName,StStr.strBr);
                if ( SectionName == StrNewSection )
                {
                    if ( !string.IsNullOrEmpty(PageName) && ( rblUsePageName.SelectedValue == "Yes" ) )
                    {
                        //SectionName             =   string.Format("{0} {1}",entDisplayName,PageName);
                        SectionName             =   PageName;
                    }
                    else 
                    {
                        if ( !string.IsNullOrEmpty( TbSectionName.Text) )
                            SectionName         =   TbSectionName.Text;
                        else SectionName        =   string.Format("{0} {1}",entDisplayName,PageName);
                    }
                    fmt                         =   LocalizeHelper.Localize("ATTACH2CRM_SUMMARYFMT3B","New Section name: {0}{1}");
                    sb.AppendFormat(fmt, SectionName,StStr.strBr);
                }
                else
                {
                    fmt                         =   LocalizeHelper.Localize("ATTACH2CRM_SUMMARYFMT3B","Section name: {0}{1}");
                    sb.AppendFormat(fmt, SectionName,StStr.strBr);
                }
            }
            int wPageId                     =   int.Parse(PagesDropDownList.SelectedValue);
            string url                      =   HttpUrlBuilder.BuildUrlWithCustomAttributes(wPageId,string.Format("{0}=1",CrmStr.strCrmMark));
            fmt                             =   LocalizeHelper.Localize("ATTACH2CRM_SUMMARYFMT5","Url : {0}{1}");
            sb.AppendFormat(fmt, url,StStr.strBr);
            fmt                             =   LocalizeHelper.Localize("ATTACH2CRM_SUMMARYFMT6","Click on Update Button to proceed.");
            if ( init )
                sb.AppendFormat(fmt, url,StStr.strBr);
            Literal lit                     =   new Literal();
            lit.Text                        =   sb.ToString();
            PnSummary.Controls.Add(lit);
        }

        void RadTabStrip1_TabClick(object sender, RadTabStripEventArgs e)
        {
            if (ModuleTraceSwitch.Sw.TraceVerbose)
                Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]Attach2CrmForm RadTabStrip1_TabClick  BEG TabIndex: {0}.", e.Tab.TabIndex), ModuleTraceSwitch.Sw.Info);
            // We go back in expert
            if (RadTabStrip1.SelectedTab.Index > e.Tab.Index)
                return;
            switch (e.Tab.TabIndex)
            {
                case 2:
                    FillTree();
                    return;
                case 3:
                    FillSummary(true);
                    return;
            }
        }

        void RadComboTab_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
        {
            string selTab               =   string.Format("Tab '{0}'",RadComboTab.SelectedItem.Text);
            string TabId                =   RadComboTab.SelectedItem.Value;
            if (ModuleTraceSwitch.Sw.TraceVerbose)
                Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]Attach2CrmForm RadComboTab_SelectedIndexChanged BEG selTab: {0}, TabId: {1}",selTab,TabId),ModuleTraceSwitch.Sw.Info);
            RadComboSection.ClearSelection();
            RadComboSection.Items.Clear();
            RadComboBoxItem it0         =   new RadComboBoxItem(StrNewSection,string.Empty);
            RadComboSection.Items.Add(it0);
            it0.Selected                =   true;
            if ( TabId != string.Empty )
            {
                string selectedEntity   =   RadComboEntities.SelectedValue;
                CrmUtil4Form util       =   new CrmUtil4Form((CrmWrapper4)Wrapper, selectedEntity);
                util.ExportXml();
                TreeUtil fTree          =   util.BuildTree(true, true);
                FindSectionsInTab(TabId, fTree.Node, false);
            }
        }
        /// <summary>
        /// Use EntityBuilder to Build entity
        /// </summary>
        void Attach2CrmFrame_ADNUpdateModule(object sender, ModuleEventArgs e)
        {
            if (!Page.IsValid)
            {
                if (ModuleTraceSwitch.Sw.TraceVerbose)
                    Trace2.WriteLine( "[V]Attach2CrmForm Attach2CrmFrame_ADNUpdateModule : Page not valid",ModuleTraceSwitch.Sw.Info);
                e.Cancel                        =   true;
                return;
            }
            try
            {
                string entDisplayName           =   RadComboEntities.Text;
                string entName                  =   RadComboEntities.SelectedValue;
                if (ModuleTraceSwitch.Sw.TraceVerbose)
                        Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]Attach2CrmForm Attach2CrmFrame_ADNUpdateModule BEG Build Entity: {0}",entName),ModuleTraceSwitch.Sw.Info);
                int wPageId                     =   int.Parse(PagesDropDownList.SelectedValue);
                string TabName                  =   RadComboTab.Text;
                string SectionName              =   RadComboSection.Text;
                string TabId                    =   RadComboTab.SelectedValue;
                string SectionId                =   RadComboSection.SelectedValue;
                if (ModuleTraceSwitch.Sw.TraceVerbose)
                        Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]Attach2CrmForm Attach2CrmFrame_ADNUpdateModule PageId: {0}, Tab: {1}, Section: {2}, ,TabId: {3}, SectionId: {4}",
                                            new object[]{wPageId,TabName,SectionName,TabId,SectionId}),ModuleTraceSwitch.Sw.Info);
                string url                      =   HttpUrlBuilder.BuildUrlWithCustomAttributes(wPageId,string.Format("{0}=1",CrmStr.strCrmMark));
                if (ModuleTraceSwitch.Sw.TraceVerbose)
                        Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]Attach2CrmForm Attach2CrmFrame_ADNUpdateModule Url: {0}",url),ModuleTraceSwitch.Sw.Info);
                CrmUtil4Form util               =   new CrmUtil4Form((CrmWrapper4)Wrapper, entName);
                util.entityDisplayName          =   entDisplayName;
                bool ret                        =   false;
                if ( TabName == StrNewTab )
                {
                    string PageName             =   PagesDropDownList.Text;
                
                    if ( !string.IsNullOrEmpty(PageName) && ( rblUsePageName.SelectedValue == "Yes" ) )
                    {
                        util.iFrameTabName      =   PageName;
                        util.iFrameSectionName  =   PageName;
                    }
                    else 
                    {
                        if ( !string.IsNullOrEmpty(TbTabName.Text) )
                            util.iFrameTabName  =   TbTabName.Text;
                        else util.iFrameTabName =   string.Format("{0} {1}",entDisplayName,PageName);
                        if ( !string.IsNullOrEmpty( TbSectionName.Text) )
                            util.iFrameSectionName  =   TbSectionName.Text;
                        else util.iFrameSectionName =   string.Format("{0} {1}",entDisplayName,PageName);

                    }
                    ret                         =   util.AddNewIframe(url,true);
                }
                else if ( SectionName == StrNewSection )
                {
                    string PageName             =   PagesDropDownList.Text;
                
                    if ( !string.IsNullOrEmpty(PageName) && ( rblUsePageName.SelectedValue == "Yes" ) )
                    {
                        util.iFrameSectionName  =   PageName;
                    }
                    else 
                    {
                        if ( !string.IsNullOrEmpty( TbSectionName.Text) )
                            util.iFrameSectionName  =   TbSectionName.Text;
                        else util.iFrameSectionName =   string.Format("{0} {1}",entDisplayName,PageName);
                    }
                    ret                         =   util.AddNewIframe(TabId,url,true);
                }
                else
                    ret                         =   util.AddNewIframe(TabId,SectionId,url,true);
                if (ret)
                {
                    FillSummary(false);
                    StringBuilder sb            =   new StringBuilder();
                    sb.AppendFormat("LCID : {0}{1}{1}", util.LCID,StStr.strBr);
                    string fmt                  =   LocalizeHelper.Localize("ATTACH2CRM_SUCCESSMSGFMT1","IFrame successfully Created in Tab: {0}, Section: {1}, Control: {2}.<br />");
                    sb.AppendFormat(fmt,util.iFrameTabName,util.iFrameSectionName,util.iFrameName);
                    fmt                         =   LocalizeHelper.Localize("ATTACH2CRM_SUCCESSMSGFMT2","Entity {0} published.");
                    sb.AppendFormat(fmt,entDisplayName);
                    Literal lit                 =   new Literal();
                    lit.Text                    =   sb.ToString();
                    PnSummary.Controls.Add(lit);
                    // invalidate update button
                    updateBtn.Enabled           =   false;
                }
                else
                {
                    StringBuilder sb            =   new StringBuilder();
                    sb.AppendFormat("Error creating IFrame : {0}","Error in Tab or Section");
                    Literal lit                 =   new Literal();
                    lit.Text                    =   sb.ToString();
                    PnSummary.Controls.Add(lit);
                }
            }
            catch (SoapException sex)
            {
                if (ModuleTraceSwitch.Sw.TraceError)
                    Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[E]Attach2CrmForm Attach2CrmFrame_ADNUpdateModule soap ex :{0}", sex), ModuleTraceSwitch.Sw.Info);
                StringBuilder sb        =   new StringBuilder();
                sb.AppendFormat("Error: <br />{0}<br />",ErrorCodes.GetErrorMessage(sex));
                PnSummary.Controls.Add(new LiteralControl(sb.ToString()));
                e.Cancel                =   true;
                return;
            }
            catch (Exception ex)
            {
                if (ModuleTraceSwitch.Sw.TraceError)
                    Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[E]Attach2CrmForm Attach2CrmFrame_ADNUpdateModule ex :{0}", ex), ModuleTraceSwitch.Sw.Info);
                throw;
            }
        }

        /// <summary>
        /// Reset all values and displat first Tab
        /// </summary>
        void ResetBtn_Click(object sender, ImageClickEventArgs e)
        {
            PnSummary.Controls.Clear();
			RadTab Tab                  =   RadTabStrip1.Tabs[0];
			Tab.Enabled                 =   true;
			Tab.Selected                =   true;
            RadPageView PageView        =   RadMultiPage1.PageViews[0];
			PageView.Selected           =   true;
			Tab                         =   RadTabStrip1.Tabs[1];
			Tab.Enabled                 =   false;
			Tab                         =   RadTabStrip1.Tabs[2];
			Tab.Enabled                 =   false;
            
            RadFormTree.UnselectAllNodes();
            RadFormTree.Nodes.Clear();
            
            RadComboTab.ClearSelection();
            RadComboTab.Items.Clear();
            RadComboSection.ClearSelection();
            RadComboSection.Items.Clear();
            
            updateBtn.Enabled           =   true;
        }

        void BtnNext_Click(object sender, ImageClickEventArgs e)
        {
            int idx                 =   RadTabStrip1.SelectedIndex;
            if (ModuleTraceSwitch.Sw.TraceVerbose)
                Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]Attach2CrmForm BtnNext_Click  BEG TabIndex: {0}.",idx),ModuleTraceSwitch.Sw.Info);
			RadTab Tab              =   RadTabStrip1.Tabs[idx+1];
			Tab.Enabled             =   true;
			Tab.Selected            =   true;
            RadPageView PageView    =   RadMultiPage1.PageViews[idx+1];
			PageView.Selected       =   true;
            if ( idx == 0 )
                FillTree();
            else if ( idx == 1)
                FillSummary(true);
            if (ModuleTraceSwitch.Sw.TraceVerbose)
                Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]Attach2CrmForm BtnNext_Click  END New Tab Index: {0}.",Tab.Index),ModuleTraceSwitch.Sw.Info);
		}

        #region Std Overrides
 
        public override void Page_PreInit(object sender, EventArgs e)
        {
            base.Page_PreInit(sender, e);
            string strcult      =   Helpers.LocalizeHelper.GetCurrentNeutralCultureName();
            updateBtn.SkinID    =   "Update_" + strcult;
            ResetBtn.SkinID     =   "Reset_" + strcult;
            BtnNext.SkinID      =   "setupnext_" + strcult;
            BtnNext2.SkinID     =   "setupnext_" + strcult;
        }

        override protected void OnInit(EventArgs e)
        {
            InitializeComponent();
            base.OnInit(e);
        }

        private void InitializeComponent()
        {
            Load                                +=  new System.EventHandler(Page_Load);
            ADNUpdateModule                     +=  new PortalModuleEventHandler(Attach2CrmFrame_ADNUpdateModule);
            ResetBtn.Click                      +=  new ImageClickEventHandler(ResetBtn_Click);
            RadTabStrip1.TabClick               +=  new RadTabStripEventHandler(RadTabStrip1_TabClick);
            BtnNext.Click                       +=  new ImageClickEventHandler(BtnNext_Click);
            BtnNext2.Click                      +=  new ImageClickEventHandler(BtnNext_Click);
            RadComboTab.SelectedIndexChanged    +=  new RadComboBoxSelectedIndexChangedEventHandler(RadComboTab_SelectedIndexChanged);
            PagesDropDownList.IncludeAdmin      =   Settings[AStr.showAdmin].ToBool();
            PagesDropDownList.SkipList          =   Settings[AStr.skipList].Value;
        }

        #endregion
    }
}